package com.mm.base.config.mybatis;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 描述: MyBatisPlus 配置
 *
 * 开启事务
 * @EnableTransactionManagement
 *
 * @author: yanglin
 * @Date: 2021-03-04-15:37
 * @Version: 1.0
 */
@EnableTransactionManagement
@MapperScan("com.mm.mapper")
@Configuration
public class MybatisPlusConfig {

    /**
     * 开启mybatis-plus分页功能
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }


    /**
     * 自定义批量操作 Mysql
     * @return
     */
    @Bean
    public EasySqlInjector easySqlInjector() {
        return new EasySqlInjector();
    }

    @Bean
    public GlobalConfig globalConfiguration() {
        GlobalConfig conf = new GlobalConfig();
        // 自定义的注入需要在这里进行配置
        conf.setSqlInjector(easySqlInjector());
        return conf;
    }
}
